<template>
  <div>
    <!-- <web-question-block
      v-if="ttsa.controller && ttsa.mode === MODE.QA && !ttsa.voiceLoading && chatBarRef.asrType === 'text' && ttsa.questions.length"
      @item-click="onChart"
    /> -->
    <div v-if="hiddenTabBar" class="voice-in"></div>
    <div class="absolute left-0 right-0 bottom-0 z-11 w-full h-[82px]" :class="{ 'wrapper': !hiddenTabBar && !show }">
      <div class="tab-bar-container relative w-full h-full"
        :class="{ 'change-tab-bar': show || hiddenTabBar, 'qa-mode-bg': !qaStatus }">
        <div class="mode-item left-item absolute" :class="{ 'no-click': !qaStatus }"
          @click="qaStatus && $emit('on-change-immerse-mode')">
          <div class="mode-text">
            沉浸模式
          </div>
          <svg-icon name="mouse" class="mode-icon" color="transparent" />
        </div>
        <div v-if="qaStatus" class="explain-mode absolute flc" :class="{ pause: !ttsa?.paused }">
          <svg-icon :name="explain_status_icon" class="switch-icon" color="transparent" @click="handleSwitchPlayStatus" />
          <svg-icon name="arc" class="arc-item absolute left-1/2 bottom-[-26px]" />
        </div>
        <div class="mode-item right-item absolute" @click="onHandQa">
          <svg-icon :name="qaStatus ? 'qa' : 'explain'" class="mode-icon mr-2px" color="transparent" />
          <div class="mode-text">
            {{ qaStatus ? '提问模式' : '讲解模式' }}
          </div>
        </div>
      </div>
      <div class="qa-bar" :class="{ 'change-tab-bar': show, 'move-end': qaStatus, 'move-start': !qaStatus }">
        <questions-and-answers-bar ref="chatBarRef" class="-top-[82px]" @change-qa-type="handleHiddenTabBar" />
      </div>
    </div>
  </div>
</template>
<script lang="ts" name="TabBar" setup>
import { useTtsaStore } from '@/store/ttsa';
import { PROCESS_TYPES, MODE } from '@/constants/ttsa';

defineEmits(['on-change-immerse-mode']);
defineProps({
  show: {
    type: Boolean,
    default: false,
    required: false,
  },
});
const ttsa = useTtsaStore();
const chatBarRef = ref(null);
const qaStatus = computed(() => (ttsa.mode !== MODE.QA));// 提问/讲解
const hiddenTabBar = ref(false);

const onHandQa = () => {
  if (ttsa.mode === MODE.QA) {
    ttsa.qaToExplain();
  } else {
    ttsa.explainToQa();
  }
};

// 提问
const onChart = (content) => {
  ttsa.chat(content)
}

// 播放/暂停
const explain_status_icon = computed(() => {
  return ttsa.paused ? 'pc-pause' : 'pc-play';
});

const handleSwitchPlayStatus = () => {
  ttsa?.paused ? (ttsa?.process === PROCESS_TYPES.idle_response ? ttsa.next() : ttsa.goon()) : ttsa.pause();
}

const handleHiddenTabBar = (value) => {
  hiddenTabBar.value = value;

}
</script>
<style lang="scss" scoped>
.tab-bar-container {
  user-select: none;
  background-image: url('@/assets/images/pc/tabbar.svg');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-clip: padding-box;
  transition: all 0.6s ease-out;

  .explain-mode {
    width: 95px;
    height: 95px;
    left: 50%;
    transform: translateX(-50%);
    top: -76px;
    z-index: 0;
    transition: all 0.3s ease;

    .switch-icon {
      width: 77px;
      height: 77px;
      position: relative;
      cursor: pointer;
    }

    &::before {
      width: 100%;
      height: 100%;
      content: "";
      border-radius: 50%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1;
      box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.15);
      background: rgba(237, 248, 252, 0.25);
      backdrop-filter: blur(4px);
      opacity: 0;
      animation: wave-play 3s linear infinite;
    }

    &::after {
      width: 100%;
      height: 100%;
      content: "";
      border-radius: 50%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: -2;
      box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.15);
      background: rgba(237, 248, 252, 0.25);
      backdrop-filter: blur(4px);
      opacity: 0;
      animation: wave-play 3s linear 0.8s infinite;
    }

    @keyframes wave-play {
      from {
        transform: scale(0.2);
        opacity: 0;
      }

      50% {
        transform: scale(1);
        opacity: 1;
      }

      to {
        transform: scale(1.5);
        opacity: 0;
      }
    }

    &.pause::before,
    &.pause::after {
      animation: none;
    }
  }

  .mode-item {
    display: flex;
    justify-content: center;
    align-items: center;
    top: 18px;
    width: 170px;
    height: 48px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 25px;
    backdrop-filter: blur(2px);
    cursor: pointer;
    transition: all 0.6s ease-out;

    &:hover {
      background: rgba(255, 255, 255, 0.3);
      border: 1px solid rgba(255, 255, 255, 0.8);
    }
  }

  .arc-item {
    width: 108px;
    height: 13px;
    transform: translateX(-50%);
    transition: all 0.6s ease-out;
  }

  .no-click {
    cursor: not-allowed;
    opacity: 0.3;

    &:hover {
      background: rgba(255, 255, 255, 0.15);
      border: none;
    }
  }

  .left-item {
    left: 32%;
    transform: translateX(-32%);
  }

  .right-item {
    right: 32%;
    transform: translateX(32%);
  }

  .mode-text {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 18px;
    font-weight: 600;
    color: #FFFFFF;
    line-height: 30px;
    letter-spacing: 1px;
    text-shadow: 0px 2px 4px rgba(10, 22, 51, 0.4);
  }

  .mode-icon {
    width: 40px;
    height: 40px;
  }

  &::before {
    content: '';
    position: absolute;
    top: -112px;
    left: 0;
    width: 100%;
    height: 195px;
    background: linear-gradient(180deg, rgba(103, 148, 183, 0) 0%, #526F82 100%);
    opacity: 0.38;
  }
}

.qa-mode-bg {
  background-image: url('@/assets/images/pc/question-mode.svg');

  .left-item {
    left: 10%;
  }

  .right-item {
    right: 10%;
  }
}

.change-tab-bar {
  transform: translateY(61px);
}

.move-end {
  $t: 0.18s;

  @keyframes content-end {
    from {
      transform: scaleX(1);
      opacity: 1;
    }

    to {
      transform: scaleX(0);
      opacity: 0;
    }
  }

  animation: content-end $t linear calc($t / 2) both;
}

.move-start {
  $t: 0.3s;

  @keyframes content-start {
    from {
      transform: scaleX(0);
      opacity: 0;
    }

    to {
      transform: scaleX(1);
      opacity: 1;
    }
  }

  animation: content-start $t linear calc($t / 2) both;
}

.qa-bar {
  transition: all 0.6s ease-out;
}

.wrapper {
  &::before {
    @apply absolute left-0 top-0 w-full h-full backdrop-filter backdrop-blur-[3px];
    content: '';
  }
}

.voice-in {
  @apply absolute right-0 bottom-0 left-0 w-full;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 100%);
  height: 320px;
}

@media screen and (max-width: 1200px) {
  .qa-mode-bg {

    .left-item {
      left: 2%;
    }

    .right-item {
      right: 2%;
    }
  }
}

/*当页面宽度大于1280px且小于1366px的时候执行,1280-1366*/
@media screen and (min-width:1280px) and (max-width: 1366px) {
  .qa-mode-bg {

    .left-item {
      left: 10%;
    }

    .right-item {
      right: 10%;
    }
  }
}

/*当页面宽度大于1440px且小于1600px的时候执行,1440-1600*/
@media screen and (min-width:1440px) and (max-width:1600px) {
  .qa-mode-bg {

    .left-item {
      left: 13%;
    }

    .right-item {
      right: 13%;
    }
  }
}

/*当页面宽度大于1680px且小于1920px的时候执行,1680-1920*/
@media screen and (min-width:1680px) and (max-width:1920px) {
  .qa-mode-bg {

    .left-item {
      left: 15%;
    }

    .right-item {
      right: 15%;
    }
  }
}

/*当页面宽度大于1920px*/
@media screen and (min-width:1920px) {
  .qa-mode-bg {

    .left-item {
      left: 18%;
    }

    .right-item {
      right: 18%;
    }
  }
}
</style>
